var GRID_HEADER = '<table width="100%" cellspacing="0" cellpadding="0" border="0" class="grid" style="table-layout: fixed;" id="grid">';
var GRID_FOOTER = '</table>';
var ROW_HEADER = '<tr onmousemove="GridSwitchOn(this)" onmouseout="GridSwitchOff(this)"  class="gridrow">';
var ROW_FOOTER = '</tr>';

function GetIconCell(crmId, entityName, tooltipText) {
    return '<td onclick="CellClick(this);" id="' + crmId + '" type="' + entityName + '" width="20" class="gridcell" align="center"><img alt="' + tooltipText + '" src="icons/' + entityName + '.gif" width="16" height="16" border="0" /></td>';
}

function GetTextCell(crmId, entityName, tooltipText, displayText) {
    var cellWidth = "";
    if (displayText == "") cellWidth = ' width="18"';
    return '<td onclick="CellClick(this);" id="' + crmId + '" type="' + entityName + '" title="' + tooltipText + '" ' + cellWidth + ' class="gridcell"><nobr>' + displayText + '&nbsp;</nobr></td>';
}

function GetDateCell(crmId, entityName, tooltipText, displayText) {
    return '<td onclick="CellClick(this);" id="' + crmId + '" type="' + entityName + '" title="' + tooltipText + '" width="37" class="gridcell"><nobr>' + displayText + '&nbsp;</nobr></td>';
}

function GetRow(crmId, entityName, entityNameDisplay, activitySubject, activityDate, parentId, parentType, parentName) {
    var rowHtml = '';
    rowHtml += GetIconCell(crmId, entityName, entityNameDisplay);
    rowHtml += GetTextCell(crmId, entityName, activitySubject, activitySubject);
    rowHtml += GetDateCell(crmId, entityName, activityDate, activityDate.toString().substr(0, 6));
    if (parentId == "")
        rowHtml += GetTextCell(crmId, entityName, activitySubject, "");    
    else
        rowHtml += GetIconCell(parentId, parentType, parentName);
    return rowHtml;
}

function CellClick(cell) {
    var url = 'http://' + CRM_SERVER + '/' + CRM_ORGANIZATION + '/' + GetFormUrl(cell.type) + '?id=' + cell.id;
    System.Shell.execute(url);
}

function GridSwitchOn(row) {
    row.style.backgroundColor = '#a7cdf0';
}

function GridSwitchOff(row) {
    row.style.backgroundColor = '#ffffff';
}